/*
-------------------------------------------------

	Autumn.cpp

	Dmitriy Kuzmenko (Dgut)

-------------------------------------------------
*/

#include "Autumn.h"
#include "Audio.h"
#include "Common.h"
#include "Console.h"
#include "File.h"
#include "Input.h"
#include "Render.h"
#include "XML.h"
#include <stdarg.h>

namespace Autumn
{

Autumn::Autumn( void )
{
}

Autumn::~Autumn( void )
{
}

Sound * const Autumn::GetSound( const char * name ) const
{
	return gAudio.GetSound( name );
}

const bool Autumn::PlaySound( const Sound * sound ) const
{
	return gAudio.PlaySound( sound );
}

void Autumn::PlayStream( const char * name ) const
{
	gAudio.PlayStream( name );
}

void Autumn::SoundEnable( bool enable ) const
{
	gAudio.SoundEnable( enable );
}

const bool Autumn::IsSoundEnable( void ) const
{
	return gAudio.IsSoundEnable();
}

void Autumn::MusicEnable( bool enable ) const
{
	gAudio.MusicEnable( enable );
}

const bool Autumn::IsMusicEnable( void ) const
{
	return gAudio.IsMusicEnable();
}

const int Autumn::Delta( void ) const
{
	return gCommon.DELTA;
}

const int Autumn::Time( void ) const
{
	return gCommon.TIME;
}
	
const int Autumn::Width( void ) const
{
	return gCommon.WIDTH;
}

const int Autumn::Height( void ) const
{
	return gCommon.HEIGHT;
}

void Autumn::Save( void ) const
{
	gCommon.Save();
}

const bool Autumn::Load( void ) const
{
	return gCommon.Load();
}

void Autumn::Log( const char * text, ... )
{
	//static char buffer[ 1024 ] = { 0 };
	char buffer[ 1024 ];

	va_list	arg;
	
	va_start( arg, text );
	vsnprintf( buffer, sizeof( buffer ), text, arg );
	va_end( arg );

	gConsole.Log( buffer );
}

const char * const Autumn::GetLog( int line ) const
{
	return gConsole.GetLog( line );
}

void Autumn::SetVariable( const char * name, const char * value )
{
	gConsole.SetVariable( name, value );
}

const char * const Autumn::GetVariable( const char * name ) const
{
	return gConsole.GetVariable( name );
}

const float Autumn::GetVariableFloat( const char * name ) const
{
	return gConsole.GetVariableFloat( name );
}

void Autumn::AddCommand( const char * name, void ( * command )( int, const char * * ) )
{
	gConsole.AddCommand( name, command );
}

void Autumn::Execute( const char * text )
{
	gConsole.Execute( text );
}

FILE * const Autumn::OpenFile( const char * name, const char * mode ) const
{
	return gFile.Open( name, mode );
}

void Autumn::Frame( void ) const
{
	gGame.Frame();
}

void Autumn::Draw( void ) const
{
	gGame.Draw();
}

const float * const Autumn::GetTouches( void ) const
{
	return gInput.GetTouches();
}

const int Autumn::GetNumTouches( void ) const
{
	return gInput.GetNumTouches();
}

const bool Autumn::GetKey( int key ) const
{
	return gInput.GetKey( key );
}
	
const bool Autumn::IsDown( float x, float y, float width, float height ) const
{
	return gInput.IsDown( x, y, width, height );
}

const bool Autumn::IsMove( float x, float y, float width, float height ) const
{
	return gInput.IsMove( x, y, width, height  );
}

const bool Autumn::IsEnter( float x, float y, float width, float height ) const
{
	return gInput.IsEnter( x, y, width, height  );
}

const bool Autumn::IsUp( float x, float y, float width, float height ) const
{
	return gInput.IsUp( x, y, width, height  );
}

const bool Autumn::IsDown( void ) const
{
	return gInput.IsDown();
}

const bool Autumn::IsUp( void ) const
{
	return gInput.IsUp();
}

const bool Autumn::IsMove( void ) const
{
	return gInput.IsMove();
}

const bool Autumn::IsKeyDown( int key ) const
{
	return gInput.IsKeyDown( key );
}

const bool Autumn::IsKeyUp( int key ) const
{
	return gInput.IsKeyUp( key );
}

Texture * const Autumn::GetTexture( const char * name ) const
{
	return gRender.GetTexture( name );
}

Font * const Autumn::GetFont( const char * name ) const
{
	return gRender.GetFont( name );
}

void Autumn::SetTexture( const Texture * texture ) const
{
	return gRender.SetTexture( texture );
}

void Autumn::SetFont( const Font * font ) const
{
	return gRender.SetFont( font );
}

void Autumn::SetOrthogonalProjection( float width, float height ) const
{
	gRender.SetOrthogonalProjection( width, height );
}

void Autumn::SetPerspectiveProjection( float fov ) const
{
	gRender.SetPerspectiveProjection( fov );
}

void Autumn::PushMatrix( void ) const
{
	gRender.PushMatrix();
}

void Autumn::PopMatrix( void ) const
{
	gRender.PopMatrix();
}

void Autumn::Identity( void ) const
{
	gRender.Identity();
}

void Autumn::Rotate( float angle ) const
{
	gRender.Rotate( angle );
}

void Autumn::Rotate( float angle, float x, float y, float z ) const
{
	gRender.Rotate( angle, x, y, z );
}

void Autumn::Scale( float scale ) const
{
	gRender.Scale( scale );
}

void Autumn::Scale( float x, float y, float z ) const
{
	gRender.Scale( x, y, z );
}

void Autumn::Translate( float x, float y, float z ) const
{
	gRender.Translate( x, y, z );
}

void Autumn::SetColor( float red, float green, float blue, float alpha ) const
{
	gRender.SetColor( red, green, blue, alpha );
}

void Autumn::DrawRectangle( float x, float y, float width, float height ) const
{
	gRender.DrawRectangle( x, y, width, height );
}

void Autumn::DrawPolygon( float * verts, float * tverts, int numPoints ) const
{
	gRender.DrawPolygon( verts, tverts, numPoints );
}

void Autumn::Print( Font::HorizontalAlign ha, Font::VerticalAlign va, float x, float y, float scale, const char * text, ... ) const
{
	//static char buffer[ 1024 ] = { 0 };
	char buffer[ 1024 ];

	va_list	arg;
	
	va_start( arg, text );
	vsnprintf( buffer, sizeof( buffer ), text, arg );
	va_end( arg );

	gRender.Print( ha, va, x, y, scale, buffer );
}

Screen * const Autumn::GetScreen( void ) const
{
	return gUI.GetScreen();
}

void Autumn::SetScreen( Screen * screen ) const
{
	gUI.SetScreen( screen );
}

pugi::xml_document * const Autumn::LoadXML( const char * name ) const
{
	return gXML.Load( name );
}

const bool Autumn::SaveXML( pugi::xml_document * doc, const char * name ) const
{
	return gXML.Save( doc, name );
}

}	// namespace Autumn